<?php

use yii\db\Migration;
use yii\db\Schema;

/**
 * Class m181026_081146_ADD_FIELD_PRODUCT
 */
class m181026_081146_ADD_FIELD_PRODUCT extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->addColumn('{{product}}', 'customer_code', Schema::TYPE_STRING. "(255) NULL COMMENT '客户团号' AFTER customer_id ");

        $this->addColumn('{{invoice}}', 'pay_type', Schema::TYPE_INTEGER. "(2) NOT NULL DEFAULT '1' COMMENT '支付方式' AFTER price ");

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

        // invoice 详情
        $this->createTable('invoice_detail', [
            "id" =>             Schema::TYPE_PK,
            "invoice_id" =>     Schema::TYPE_INTEGER.   "(10) NOT NULL DEFAULT '0' COMMENT 'invoice ID'",

            "num" =>     Schema::TYPE_INTEGER.   "(10) NOT NULL DEFAULT '0' COMMENT '数量'",
            "s_price" => Schema::TYPE_DECIMAL.   "(10,2) DEFAULT '0.00' COMMENT '单价金额' ",
            "t_price" => Schema::TYPE_DECIMAL.   "(10,2) DEFAULT '0.00' COMMENT '总金额' ",

            "remark" =>        Schema::TYPE_STRING.    "(1024)  NULL COMMENT '备注'",

            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",
            "created_at" =>     Schema::TYPE_DATETIME. " NULL COMMENT '创建时间'",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);

    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        echo "m181026_081146_ADD_FIELD_PRODUCT cannot be reverted.\n";

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m181026_081146_ADD_FIELD_PRODUCT cannot be reverted.\n";

        return false;
    }
    */
}
